﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace dreametryVersion2
{
    public partial class frmOutputDescription : Form
    {
        String display;
        String output;
        String task_id;

        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int HT_CAPTION = 0x2;
        [DllImportAttribute("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        [DllImportAttribute("user32.dll")]
        public static extern bool ReleaseCapture();
        public frmOutputDescription()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            output = null;
            this.Close();
        }

        private void frmOutputDescription_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            display = display + txtName.Text + Environment.NewLine;
            lblOutput.Text = display;

            

            output = output + "<a href =" + txtLink.Text + ">" + txtName.Text + "</a ><br>";

            txtLink.Text = "";
            txtName.Text = "";
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            //update database
            String query = "UPDATE TaskTable SET output_description ='" + output + "' WHERE task_id='"+ task_id + "'";
            using (SqlConnection conn = new SqlConnection(global.conString))
            {
                conn.Open();
                SqlCommand command = new SqlCommand(query, conn);
                command.ExecuteNonQuery();
            }

            this.Close();
        }

        public String show(String id)
        {
            task_id = id;
            this.ShowDialog();
            return output;
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            output = "";
            display = "";
            lblOutput.Text = display;
        }

        private void frmOutputDescription_Load(object sender, EventArgs e)
        {
            this.BackColor = ColorTranslator.FromHtml(global.themeColor);
            btnAdd.BackColor = ColorTranslator.FromHtml(global.themeColor);
            btnOk.BackColor = ColorTranslator.FromHtml(global.themeColor);
            btnClear.BackColor = ColorTranslator.FromHtml(global.themeColor);
            panel1.BackColor = ColorTranslator.FromHtml(global.themeColor);
            panel2.BackColor = ColorTranslator.FromHtml(global.themeColor);
        }
    }
}
